import Vue from 'vue'
import App from './App.vue'
import router from './router'
// import './plugins/element.js'
import './assets/global.css'
import './assets/fonts/iconfont.css'
import TreeTable from 'vue-table-with-tree-grid'
// 富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

// 进度条插件
import NProgress from 'nprogress'

import axios from 'axios'
// 配置基本接口地址
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

axios.interceptors.request.use(config => {
  // 在request拦截器展示进度条NProgress.start()
  NProgress.start()
  // token拦截验证 所有非登陆界面需要
  // console.log(config.headers.Authorization)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 必须return config
  return config
})

axios.interceptors.response.use(config => {
  // 再response拦截器隐藏进度条 NProgress.done()
  NProgress.done()
  // 必须return config
  return config
})
// 把axios挂载到Vue原型对象可以直接用this.$http访问
Vue.prototype.$http = axios

Vue.config.productionTip = false
Vue.component('tree-table', TreeTable)
Vue.use(VueQuillEditor)
// 时间过滤器
Vue.filter('dateFormat', originVal => {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
// 卸载应用
window.unmount = () => {
  app.$destroy()
}
